package com.imut.lagain.entity;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.persistence.Column;
import jakarta.persistence.PreUpdate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;

/**
 * 答案锁提醒实体类
 */
@TableName("answer_lock_reminder")
public class AnswerLockReminder {
    private static final Logger log = LoggerFactory.getLogger(AnswerLockReminder.class);


    @TableId(type = IdType.AUTO)
    private Long id;

    @TableField("lock_id")
    private Long lockId;

    @TableField("user_id")
    private Long userId;

    @TableField("reminder_type")
    private String reminderType; // unlock_approaching/password_hint/backup_reminder/security_check

    @TableField("reminder_title")
    private String reminderTitle;

    @TableField("reminder_message")
    private String reminderMessage;

    @TableField("reminder_time")
    private LocalDateTime reminderTime;

    @TableField("advance_days")
    private Integer advanceDays = 1; // 提前多少天提醒

    @TableField("repeat_type")
    private String repeatType; // none/daily/weekly/monthly/custom

    @TableField("repeat_interval")
    private Integer repeatInterval; // 重复间隔

    @TableField("repeat_count")
    private Integer repeatCount; // 重复次数

    @TableField("max_repeats")
    private Integer maxRepeats; // 最大重复次数

    @TableField("reminder_status")
    private String reminderStatus = "active"; // active/paused/completed/cancelled/expired

    @Column(name = "is_sent", nullable = false)
    private Boolean isSent = false;

    @Column(name = "sent_at")
    private LocalDateTime sentAt;

    @Column(name = "delivery_method", nullable = false, length = 30)
    private String deliveryMethod = "wechat"; // wechat/email/sms/push/in_app

    @Column(name = "delivery_status", length = 20)
    private String deliveryStatus; // pending/sent/delivered/failed/read

    @Column(name = "delivery_attempts", nullable = false)
    private Integer deliveryAttempts = 0;

    @Column(name = "max_delivery_attempts", nullable = false)
    private Integer maxDeliveryAttempts = 3;

    @Column(name = "last_delivery_attempt")
    private LocalDateTime lastDeliveryAttempt;

    @Column(name = "delivery_error", columnDefinition = "TEXT")
    private String deliveryError;

    @Column(name = "response_required", nullable = false)
    private Boolean responseRequired = false;

    @Column(name = "response_received", nullable = false)
    private Boolean responseReceived = false;

    @Column(name = "response_time")
    private LocalDateTime responseTime;

    @Column(name = "response_content", columnDefinition = "TEXT")
    private String responseContent;

    @Column(name = "priority", nullable = false)
    private Integer priority = 1; // 1-low, 2-medium, 3-high, 4-urgent

    @Column(name = "urgency_level", length = 20)
    private String urgencyLevel = "normal"; // low/normal/high/critical

    @Column(name = "template_id", length = 100)
    private String templateId; // 消息模板ID

    @Column(name = "template_data", columnDefinition = "JSON")
    private String templateData; // 模板数据

    @Column(name = "custom_data", columnDefinition = "JSON")
    private String customData; // 自定义数据

    @Column(name = "timezone", length = 50)
    private String timezone = "Asia/Shanghai";

    @Column(name = "preferred_time", length = 20)
    private String preferredTime; // 用户偏好的提醒时间 HH:mm

    @Column(name = "quiet_hours_start", length = 20)
    private String quietHoursStart; // 免打扰开始时间

    @Column(name = "quiet_hours_end", length = 20)
    private String quietHoursEnd; // 免打扰结束时间

    @Column(name = "is_test", nullable = false)
    private Boolean isTest = false;

    @Column(name = "test_mode", length = 20)
    private String testMode; // none/preview/sandbox

    @Column(name = "tracking_id", length = 100)
    private String trackingId; // 追踪ID

    @Column(name = "campaign_id", length = 100)
    private String campaignId; // 活动ID

    @Column(name = "tags", length = 500)
    private String tags; // 标签，逗号分隔

    @Column(name = "metadata", columnDefinition = "JSON")
    private String metadata;

    @Column(name = "expires_at")
    private LocalDateTime expiresAt;

    @Column(name = "created_at", nullable = false)
    private LocalDateTime createdAt = LocalDateTime.now();

    @Column(name = "updated_at", nullable = false)
    private LocalDateTime updatedAt = LocalDateTime.now();

    @Column(name = "deleted_at")
    private LocalDateTime deletedAt;
    public AnswerLockReminder() {}

    public AnswerLockReminder(Long lockId, Long userId, String reminderType, String reminderTitle, LocalDateTime reminderTime) {
        this.lockId = lockId;
        this.userId = userId;
        this.reminderType = reminderType;
        this.reminderTitle = reminderTitle;
        this.reminderTime = reminderTime;
    }
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public Long getLockId() { return lockId; }
    public void setLockId(Long lockId) { this.lockId = lockId; }

    public Long getUserId() { return userId; }
    public void setUserId(Long userId) { this.userId = userId; }

    public String getReminderType() { return reminderType; }
    public void setReminderType(String reminderType) { this.reminderType = reminderType; }

    public String getReminderTitle() { return reminderTitle; }
    public void setReminderTitle(String reminderTitle) { this.reminderTitle = reminderTitle; }

    public String getReminderMessage() { return reminderMessage; }
    public void setReminderMessage(String reminderMessage) { this.reminderMessage = reminderMessage; }

    public LocalDateTime getReminderTime() { return reminderTime; }
    public void setReminderTime(LocalDateTime reminderTime) { this.reminderTime = reminderTime; }

    public Integer getAdvanceDays() { return advanceDays; }
    public void setAdvanceDays(Integer advanceDays) { this.advanceDays = advanceDays; }

    public String getRepeatType() { return repeatType; }
    public void setRepeatType(String repeatType) { this.repeatType = repeatType; }

    public Integer getRepeatInterval() { return repeatInterval; }
    public void setRepeatInterval(Integer repeatInterval) { this.repeatInterval = repeatInterval; }

    public Integer getRepeatCount() { return repeatCount; }
    public void setRepeatCount(Integer repeatCount) { this.repeatCount = repeatCount; }

    public Integer getMaxRepeats() { return maxRepeats; }
    public void setMaxRepeats(Integer maxRepeats) { this.maxRepeats = maxRepeats; }

    public String getReminderStatus() { return reminderStatus; }
    public void setReminderStatus(String reminderStatus) { this.reminderStatus = reminderStatus; }

    public Boolean getIsSent() { return isSent; }
    public void setIsSent(Boolean isSent) { this.isSent = isSent; }

    public LocalDateTime getSentAt() { return sentAt; }
    public void setSentAt(LocalDateTime sentAt) { this.sentAt = sentAt; }

    public String getDeliveryMethod() { return deliveryMethod; }
    public void setDeliveryMethod(String deliveryMethod) { this.deliveryMethod = deliveryMethod; }

    public String getDeliveryStatus() { return deliveryStatus; }
    public void setDeliveryStatus(String deliveryStatus) { this.deliveryStatus = deliveryStatus; }

    public Integer getDeliveryAttempts() { return deliveryAttempts; }
    public void setDeliveryAttempts(Integer deliveryAttempts) { this.deliveryAttempts = deliveryAttempts; }

    public Integer getMaxDeliveryAttempts() { return maxDeliveryAttempts; }
    public void setMaxDeliveryAttempts(Integer maxDeliveryAttempts) { this.maxDeliveryAttempts = maxDeliveryAttempts; }

    public LocalDateTime getLastDeliveryAttempt() { return lastDeliveryAttempt; }
    public void setLastDeliveryAttempt(LocalDateTime lastDeliveryAttempt) { this.lastDeliveryAttempt = lastDeliveryAttempt; }

    public String getDeliveryError() { return deliveryError; }
    public void setDeliveryError(String deliveryError) { this.deliveryError = deliveryError; }

    public Boolean getResponseRequired() { return responseRequired; }
    public void setResponseRequired(Boolean responseRequired) { this.responseRequired = responseRequired; }

    public Boolean getResponseReceived() { return responseReceived; }
    public void setResponseReceived(Boolean responseReceived) { this.responseReceived = responseReceived; }

    public LocalDateTime getResponseTime() { return responseTime; }
    public void setResponseTime(LocalDateTime responseTime) { this.responseTime = responseTime; }

    public String getResponseContent() { return responseContent; }
    public void setResponseContent(String responseContent) { this.responseContent = responseContent; }

    public Integer getPriority() { return priority; }
    public void setPriority(Integer priority) { this.priority = priority; }

    public String getUrgencyLevel() { return urgencyLevel; }
    public void setUrgencyLevel(String urgencyLevel) { this.urgencyLevel = urgencyLevel; }

    public String getTemplateId() { return templateId; }
    public void setTemplateId(String templateId) { this.templateId = templateId; }

    public String getTemplateData() { return templateData; }
    public void setTemplateData(String templateData) { this.templateData = templateData; }

    public String getCustomData() { return customData; }
    public void setCustomData(String customData) { this.customData = customData; }

    public String getTimezone() { return timezone; }
    public void setTimezone(String timezone) { this.timezone = timezone; }

    public String getPreferredTime() { return preferredTime; }
    public void setPreferredTime(String preferredTime) { this.preferredTime = preferredTime; }

    public String getQuietHoursStart() { return quietHoursStart; }
    public void setQuietHoursStart(String quietHoursStart) { this.quietHoursStart = quietHoursStart; }

    public String getQuietHoursEnd() { return quietHoursEnd; }
    public void setQuietHoursEnd(String quietHoursEnd) { this.quietHoursEnd = quietHoursEnd; }

    public Boolean getIsTest() { return isTest; }
    public void setIsTest(Boolean isTest) { this.isTest = isTest; }

    public String getTestMode() { return testMode; }
    public void setTestMode(String testMode) { this.testMode = testMode; }

    public String getTrackingId() { return trackingId; }
    public void setTrackingId(String trackingId) { this.trackingId = trackingId; }

    public String getCampaignId() { return campaignId; }
    public void setCampaignId(String campaignId) { this.campaignId = campaignId; }

    public String getTags() { return tags; }
    public void setTags(String tags) { this.tags = tags; }

    public String getMetadata() { return metadata; }
    public void setMetadata(String metadata) { this.metadata = metadata; }

    public LocalDateTime getExpiresAt() { return expiresAt; }
    public void setExpiresAt(LocalDateTime expiresAt) { this.expiresAt = expiresAt; }

    public LocalDateTime getCreatedAt() { return createdAt; }
    public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }

    public LocalDateTime getUpdatedAt() { return updatedAt; }
    public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }

    public LocalDateTime getDeletedAt() { return deletedAt; }
    public void setDeletedAt(LocalDateTime deletedAt) { this.deletedAt = deletedAt; }

    @PreUpdate
    public void preUpdate() {
        this.updatedAt = LocalDateTime.now();
    }
}
